﻿using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
using Sasc.PV.Common;
namespace Sasc.PV.DAL
{
	[Serializable]
	public partial class ERPUser
	{		
        
        #region Ctor
        public ERPUser()
        {
      	      	_id=(int)0;
      			_username= "";
      			_userpwd= "";
      			_truename= "";
      			_serils= "";
      			_department= "";
      			_jiaose= "";      	 
      			_zhiwei= "";
      			_zaigang= "";
      			_emailstr= "";
      			_iflogin= "";
      			_sex= "";
      			_backinfo= "";
      			_birthday= "";
      			_mingzu= "";
      			_sfzserils= "";
      			_hunying= "";
      			_zhengzhimianmao= "";
      			_jiguan= "";
      			_hukou= "";
      			_xueli= "";
      			_zhicheng= "";
      			_biyeyuanxiao= "";
      			_zhuanye= "";
      			_canjiagongzuotime= "";
      			_jiarubendanweitime= "";
      			_jiatingdianhua= "";
      			_jiatingaddress= "";
      			_gangweibiandong= "";
      			_jiaoyuebeijing= "";
      			_gongzuojianli= "";
      			_shehuiguanxi= "";
      			_jiangchengjilu= "";
      			_zhiwuqingkuang= "";
      			_peixunjilu= "";
      			_danbaojilu= "";
      			_naodonghetong= "";
      			_shebaojiaona= "";
      			_tijianjilu= "";
      			_beizhustr= "";
      			_fujian= "";
      			_pop3username= "";
      			_pop3userpwd= "";
      			_pop3server= "";
      			_pop3port= "";
      			_smtpusername= "";
      			_smtpuserpwd= "";
      			_smtpserver= "";
      			_smtpfromemail= "";
      			_tixingtime= "";
      			_iftixing= "";
      			_daohanglist= "";
      			_xkeguandep= "";
      			_xiashuuser= "";
                _daohangidlist = "";
       }
        #endregion

        #region Other Methods
        /// <summary>
        /// 登陆系统
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        public DataRow UserLogin(string userName, string password, string LoginType, out bool success)
        {
            string SqlSTr = "select * from ERPUser where UserName='" + Utils.ProcessSqlStr(userName) + "'";
            if (LoginType == "0")
            {
                SqlSTr = "select * from ERPUser where Serils='" + Utils.ProcessSqlStr(userName) + "'";
            }
            else if (LoginType == "1")
            {
                SqlSTr = "select * from ERPUser where UserName='" + Utils.ProcessSqlStr(userName) + "'";
            }
            else
            {
                SqlSTr = "select * from ERPUser where UserName='" + Utils.ProcessSqlStr(userName) + "' or Serils='" + Utils.ProcessSqlStr(userName) + "'";
            }

            var dataRow = DbHelperSQL.GetDataRow(SqlSTr);

            //写登陆日志
            ERPRiZhi myRiZhi = new ERPRiZhi();
            myRiZhi.UserName = userName;
            myRiZhi.DoSomething = "用户登陆系统";
            myRiZhi.IpStr = Utils.GetIPAddress();
            myRiZhi.Add(myRiZhi);

            success = dataRow != null && password == DataValidate.ValidateDataRow_S(dataRow, "UserPwd");
            return dataRow;
        }


        #endregion

        /// <summary>
        /// 通过当前用户  获取下属
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public string GetXiaShu(string username)
        {

            string sql = "select top 1 XiaShuUser from ERPUser where UserName='" + username + "'";

           return DbHelperSQL.GetSHSL(sql);
        }


        /// <summary>
        /// 修改下属
        /// </summary>
        /// <param name="username"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public int UpdateXiaShu(string username,string text)
        {

            string sql = "update ERPUser set XiaShuUser='" +text  + "' where UserName='" + username + "'";

            return DbHelperSQL.ExecuteSql(sql);
        }

    }
}